package com.wms.controller;

import com.wms.dto.GoodsInPageQueryDTO;
import com.wms.dto.GoodsOutPageQueryDTO;
import com.wms.dto.GoodsPageQueryDTO;
import com.wms.entity.WmsGoodsin;
import com.wms.entity.WmsGoodsout;
import com.wms.result.PageResult;
import com.wms.result.Result;
import com.wms.service.GoodsInService;
import com.wms.service.GoodsOutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodsout")
@Slf4j
@Api(tags = "物品出库模块")
public class GoodsOutController {
    @Autowired
    private GoodsOutService goodsOutService;

    /**
     * 出库分页查询
     * @param goodsOutPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(@RequestBody GoodsOutPageQueryDTO goodsOutPageQueryDTO){
        PageResult pageResult = goodsOutService.page(goodsOutPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除出库
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("批量删除出库")
    public Result delete(@RequestParam List<Integer> ids){
        goodsOutService.delete(ids);
        return Result.success();
    }

    /**
     * 申请出库
     * @return
     */
    @PostMapping("/applyin")
    @ApiOperation("申请出库")
    public Result applyIn(@RequestBody WmsGoodsout wmsGoodsout){
        goodsOutService.applyIn(wmsGoodsout);
        return Result.success();
    }

    /**
     * 通过审核
     * @param id
     * @return
     */
    @PostMapping("/applypass/{id}")
    @ApiOperation("出库审核")
    public Result applyPass(@PathVariable int id){
        log.info("审核申请,参数为:{}",id);
        goodsOutService.applyPass(id);
        return Result.success();
    }

    /**
     * 不通过
     * @param id
     * @return
     */
    @PostMapping("/applyfail/{id}")
    @ApiOperation("出库审核不通过")
    public Result applyFail(@PathVariable int id){
        log.info("审核申请,参数为:{}",id);
        goodsOutService.applyFail(id);
        return Result.success();
    }
}
